1.如何编译 Dart SDK
为了研究 Dart SDK,首先要下载完整的 Dart SDK 源码,并自行编译成功,基于自己编译的版本进行修改、调试。
depot_tools
首先,你需要安装 depot_tools,具体安装方式,具体包括两步:
首先,clone depot-tools 的仓库:
git clone https://chromium.googlesource.com/chromium/tools/depot_tools
之后,将其添加到 PATH
环境变量即可:
export PATH=/home/maxiee/Code/depot_tools:$PATH
如果像了解更多信息,可参见 depot-tools 官网。
拉取 dart-sdk 完整代码
如果直接从 GitHub 上 clone Dart 的 Repo,是缺少依赖的,无法编译。还是需要基于 depot-tools 中的 fetch 命令进行拉取。
mkdir dart-sdk
cd dart-sdk
fetch dart
fetch 命令不仅会拉取 Dart 代码,同时也会拉取所有相关依赖,因此耗时会比较长。
此过程的命令行展示如下:
[maxiee@archlinux dart-sdk]$ fetch dart
Running: gclient root
Running: gclient config --spec 'solutions = [
{
"name": "sdk",
"url": "https://dart.googlesource.com/sdk.git",
"deps_file": "DEPS",
"managed": False,
"custom_deps": {},
},
]
'
Updating depot_tools...
Running: gclient sync
Updating depot_tools...
________ running 'git -c core.deltaBaseCacheLimit=2g clone --no-checkout --progress https://dart.googlesource.com/sdk.git /home/maxiee/Code/dart-sdk/_gclient_sdk_6e4dx5xl' in '/home/maxiee/Code/dart-sdk'
Cloning into '/home/maxiee/Code/dart-sdk/_gclient_sdk_6e4dx5xl'...
remote: Finding sources: 100% (13/13)
Receiving objects: 29% (439204/1487479), 125.34 MiB | 1.19 MiB/s
拉取完成之后,目录下的文件如下,其中 sdk
中即为完整的 Dart SDK 源码。
Dec 11 12:55 .
Dec 11 11:33 ..
Dec 11 12:55 .cipd
Dec 11 11:47 .gclient
Dec 11 12:28 .gclient_entries
Dec 11 12:55 .gclient_previous_sync_commits
Dec 11 12:01 sdk
同时,可看到目录下生成一个 .gclient
文件,这是 gclient 的配置文件。
solutions = [
{
"name": "sdk",
"url": "https://dart.googlesource.com/sdk.git",
"deps_file": "DEPS",
"managed": False,
"custom_deps": {},
},
]
编译 Dart SDK
根据网络资源中的文章,对于 x64,编译命令如下:
./tools/build.py --no-goma --mode release --arch x64 create_sdk
执行编译后的 Dart
编译后产物位于:
dart-sdk/sdk/out/ReleaseX64
执行我们自己编译的 dart:
cd sdk/out/ReleaseX64
dart --version
# Dart SDK version: 3.2.1 (stable) (Wed Nov 22 08:59:13 2023 +0000) on "linux_x64"
Bingo!
遇到问题
ModuleNotFoundError: No module named 'imp'
原因是在 Python 3.12 中,imp
包被废弃删除了。
手动将对应文件中的 imp
模块替换为 importlib
完成。
update depot_tools failed
When I finish fetch dart
, depot_tools ask me if I want to update it. I choose Yes, but update failed:
Updating depot_tools...
Your copy of depot_tools is configured to fetch from an obsolete URL:
https://chromium.googlesource.com/chromium/tools/depot_tools
OK to update it to https://chromium.googlesource.com/chromium/tools/depot_tools.git ? [Y/n] y
Remote URL updated.
depot_tools update failed. Couldn't fetch main branch.
Retry later or reclone depot_tools
fatal: unable to access 'https://chromium.googlesource.com/chromium/tools/depot_tools.git/': CONNECT tunnel failed, response 405
Subprocess failed with return code 128.
This is related to my proxy. After I run fecth dart
without proxy, the problem is gone.
网络资源
本文作者:Maeiee
本文链接:1.如何编译 Dart SDK
版权声明:如无特别声明,本文即为原创文章,版权归 Maeiee 所有,未经允许不得转载!
喜欢我文章的朋友请随缘打赏,鼓励我创作更多更好的作品!